<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="Bookmark" href="/favicon.ico">
    <link rel="Shortcut Icon" href="/favicon.ico"/>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="lib/html5shiv.js"></script>
    <script type="text/javascript" src="lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css"/>
    <!--[if IE 6]>
    <script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js"></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <!--/meta 作为公共模版分离出去-->
    <title>产品分类编辑</title>
</head>
<body>
<div class="page-container">
    <form class="form form-horizontal" id="form1">
        <div id="tab-category" class="HuiTab">
            <div class="row cl">
                <label class="form-label col-xs-3 col-sm-2">分类名称：<span class="c-red">*</span></label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="" placeholder="" id="name" name="name">
                </div>
                <div class="col-1">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-3 col-sm-2">是否启用：</label>
                <div class="formControls col-xs-8 col-sm-9 skin-minimal">
                    <div class="radio-box">
                        <input type="radio" id="is_enable_1" name="is_enable" value="0">否
                    </div>
                    <div class="radio-box">
                        <input type="radio" id="is_enable_2" name="is_enable" value="1">是
                    </div>
                </div>
                <div class="col-1">
                </div>
            </div>
        </div>
        <div class="row cl">
            <div class="col-9 col-offset-3">
                <input type="hidden" id="id" value="">
                <button onClick="save_submit();" class="btn btn-primary radius" type="button">
                    &nbsp;&nbsp;提交&nbsp;&nbsp;
                </button>
            </div>
        </div>
    </form>
</div>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script>
<!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="/lib/common.js"></script>
<SCRIPT type="text/javascript">
    <!--
    $(function () {
        var id = getQueryString('id');
        $('#id').val(id);

        if (id) {
            $.ajax({
                url: "/api/product_class/" + id + "/",
                xhrFields: {withCredentials: true},
                type: "GET",
                dataType: 'json',
                success: function (data) {
                    if (checkLogin(data, true)) {
                        $("#name").val(data.data.name);
                        if (data.data.is_enable) {
                            $("#is_enable_2").attr('checked', 'checked');
                        }
                        else {
                            $("#is_enable_1").attr('checked', 'checked');
                        }
                    }
                }
            });
        }
    });
    function save_submit() {
        var is_enable = 0;
        if ($("input[type='radio'][name='is_enable']:checked").val() == '1') {
            is_enable = 1;
        }
        data = {
            'name': encodeURI($("#name").val()),
            'is_enable': is_enable
        };
        var id = $('#id').val();
        // 有id的是编辑，没有id值的是新增
        if (id) {
            url = "/api/product_class/" + id + "/";
            data['_method'] = 'put';
        }
        else {
            url = "/api/product_class/";
        }

        $.ajax({
            type: 'POST',
            url: url,
            xhrFields: {withCredentials: true},
            data: data,
            dataType: 'json',
            success: function (data) {
                if (checkLogin(data, true)) {
                    layer.msg(data.msg, {icon: 1, time: 3000});
                    setTimeout(function () {
                        parent.jQuery("#list").trigger("reloadGrid");
                        layer_close();
                    }, 1000);
                }
            }
        });
    }
    //-->
</SCRIPT>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>